package service

import (
	"bugManagementPlatform/pojo"
	"bugManagementPlatform/utils"
	"bugManagementPlatform/variable"
)

type UserService struct {
	Authentication *utils.Authentication
}

func NewUserService() *UserService {
	return &UserService{}
}

func (us *UserService) Login(u *pojo.User) (string, int64){

	var nu pojo.User
	variable.Db.Where("username = ? and password = ?", u.Username, u.Password).First(&nu)

	if nu.Id != 0 {
		token, expirationTime, _ := us.Authentication.GenToken(&nu)

		return token, expirationTime
	}

	return "", 0
}

